﻿using AutoMapper;
using B.S.DataBase.MyProject.ErrorCode;
using MediatR;
using S.Y.Passport.Domain.溯源;
using S.Y.Passport.ErroeCode;
using S.Y.Passport.Infacet;
using S.Y.Passport.Write.API.Applications.Commands;

namespace S.Y.Passport.Write.API.Applications.CommandHandler
{
    public class FanGoodsQueryCommandHandler : IRequestHandler<FanGoodsQueryCommand, SyResult<GoodsInfo>>
    {
        private readonly IBaseRepo<GoodsInfo> goodsInfoRepo;

        public FanGoodsQueryCommandHandler(IBaseRepo<GoodsInfo> goodsInfoRepo)
        {
            this.goodsInfoRepo = goodsInfoRepo;
        }
        public Task<SyResult<GoodsInfo>> Handle(FanGoodsQueryCommand request, CancellationToken cancellationToken)
        {
            SyResult<GoodsInfo> result = new SyResult<GoodsInfo>();
            var obj = goodsInfoRepo.GetAll().FirstOrDefault(x => x.GooodId == request.GooodId);
            if (obj == null)
            {
                result.Code = SyCode.显示失败;
                result.Msg = SyCode.显示失败.ToString();
            }
            else
            {
                result.Code = SyCode.显示成功;
                result.Msg = SyCode.显示成功.ToString();
                result.Data = obj;
            }

            return Task.FromResult(result);
        }
    }
}
